// gmx shines, thanks the great gmx
// cyx shines, thanks the great cyx
// freopen,froepen,ioi,akioi,ccf
// everyone plz, watch Arknights live
#include <bits/stdc++.h>
using namespace std;
constexpr int N(2e5);
#define int long long
int a[N+5],c[N+5];
int p[N+5],ht[N+5];
int l[N+5],r[N+5];
int D[2*N+5],TM[2*N+5],WN[2*N+5],FA[N*2+5],FRT[N*2+5],to[N*2+5];
long long res[N+5];
int K;
// void build(int p,int L,int R,int i) {
//     if (i>=R) return Q[p>>1].push_back(i),void();
//     int mid{L+R>>1};
//     build(p<<1,L,mid,i);
//     if (c[i]>mid) build(p<<1|1,mid+1,R,i);
// }
void solve(int n,int m) {
    for (int i{1};i<=(1<<K);++i)
        if (i<=n) TM[i+(1<<K)-1]=i-1,WN[i+(1<<K)-1]=a[i];
        else TM[i+(1<<K)-1]=1<<K;
    // for (int i{1};i<=m;++i) res[i]=0,p[i]=c[i],l[i]=r[i]=0;
    for (int i{1};i<=n;++i) to[i+(1<<K)-1]=FA[(i+(1<<K)-1)>>min(K,a[i])],res[i]=0;
    for (int i{(1<<K)-1};i>=1;--i) {
        if (!D[i]) {
            if (WN[i<<1]<K-__lg(i)) TM[i]=TM[i<<1|1],WN[i]=WN[i<<1|1];
            else TM[i]=TM[i<<1],WN[i]=WN[i<<1];
        } else {
            TM[i]=TM[i<<1|1];
            if (WN[i<<1|1]>=K-__lg(i)) WN[i]=WN[i<<1|1];
            else WN[i]=WN[i<<1];
        }
    }
    for (int W{0};W<=K;++W) {
        int O{(1<<K-W)-1};
        for (int i{1};i<(1<<W+1);++i)
            FRT[(O<<__lg(i))+i]=1<<K;
        for (int i{1};i<1<<W;++i) {
            int p{(O<<__lg(i))+i};
            FRT[p<<1|1]=FRT[p];
            FRT[p<<1]=FRT[p];
            if (!D[p]) {
                if (WN[p<<1]>=K-__lg(p)) FRT[p<<1|1]=min(FRT[p<<1|1],TM[p]);
                else FRT[p<<1]=min(FRT[p<<1],TM[p<<1]);
            } else {
                if (WN[p<<1|1]>=K-__lg(p)) FRT[p<<1]=min(FRT[p<<1],TM[p]);
                else FRT[p<<1|1]=min(FRT[p<<1|1],TM[p<<1|1]);
            }
        }
        for (int i{0};i<1<<W;++i) {
            int p{i+(1<<K)};
            if (i+1<=n&&to[p]>=W&&FRT[p]>=i+1&&FRT[p]>=(W?(1<<W-1):0)+1) {
                res[max(i+1,(W?(1LL<<W-1):0LL)+1)]+=i+1;
                res[min(FRT[p],1LL<<W)+1]-=i+1;
            }
            if (W>0&&i>(1<<W-1)&&FRT[p]>=(1<<W-1)) {
                res[(1<<W-1)+1]+=i+1;
                res[min(i,FRT[p])+1]-=i+1;
            }
        }
    }
    for (int i{1};i<=n;++i) res[i]+=res[i-1];
    //     if (WN[i<<1]&&WN[i<<1|1]) {
    //         if (a[WN[i<<1|D[i]]]>=K-__lg(i)) WN[i]=WN[i<<1|D[i]];
    //         else WN[i]=WN[i<<1|(!D[i])];
    //     }
    // for (int W{0};W<=K;++W) {
    //     for (int i{1};i<(1<<W);++i) {
    //         int U{0}
    //         if (!D[i]) {
    //             int T{WN[i<<1]};

    //             res[MD[i]]+=1LL*(RT[i]+MD[i]+1)*(RT[i]-MD[i])/2;
    //             TG[i<<1]+=1LL*(RT[i]+MD[i]+1)*(RT[i]-MD[i])/2;
    //         }
    //     }
    // }
    // for (int i{(1<<K)-1};i>=1;--i) {
    //     if (WN[i<<1]&&WN[i<<1|1]) {
    //         if (a[WN[i<<1|D[i]]]>=K-__lg(i)) WN[i]=WN[i<<1|D[i]];
    //         else WN[i]=WN[i<<1|(!D[i])];
    //     }
    //     if (!D[i]) {

    //     }
    //     // if (!D[i]) {
    //     //     if (a[WN[i<<1]]>=K-__lg(i))
    //     //         for (auto v:Q[i]) p[v]=RT[i],res[v]=(to[WN[i<<1]]>=ht[v])*WN[i<<1],l[v]=r[v]=a[WN[i<<1]];
    //     //     else for (auto v:Q[i]) res[v]+=1LL*(p[v]+1+RT[i])*(RT[i]-p[v])/2,p[v]=RT[i];
    //     // } else {
    //     //     int z{K-__lg(i)};
    //     //     for (auto v:Q[i]) {
    //     //         p[v]=RT
    //     //     }
    //     // }
    // }
}
signed main() {
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    cin.tie(nullptr)->sync_with_stdio(false);
    int n,m;cin>>n>>m;
    for (;(1<<K)<n;++K);
    for (int i{1};i<=n;++i) cin>>a[i];
    for (int i{1};i<=m;++i) {
        cin>>c[i];
        // ht[i]=__lg(c[i]-1);
        // if (c[i]&c[i]-1) build(1,1,1<<K,i);
    }
    // (1<<K-i)+j
    //
    for (int i{1};i<=K;++i) {
        string s;cin>>s;
        for (int j{0};j<1<<(K-i);++j)
            D[(1<<(K-i))+j]=s[j]-'0';
    }
    FA[1]=K;
    for (int i{2};i<1<<(K+1);++i)
        if ((i&1)!=D[i>>1]) FA[i]=FA[i>>1];
        else FA[i]=K-__lg(i)+1;
    int T;cin>>T;
    while (T--) {
        int x[4];
        cin>>x[0]>>x[1]>>x[2]>>x[3];
        for (int i{1};i<=n;++i) a[i]^=x[i&3];
        solve(n,m);
        long long ans{0};
        for (int i{1};i<=m;++i) ans^=1LL*i*res[c[i]];
        for (int i{1};i<=n;++i) a[i]^=x[i&3];
        cout<<ans<<endl;
    }
    return 0;
}